package com.yulongtian.weekCompetition.month202212.week4;

import java.util.ArrayList;
import java.util.List;

/**
 * 第 94 场双周赛
 *
 * @author yulongTian
 * @create 2022-12-24 22:30
 */
public class Test01 {
    public static void main(String[] args) {
        int[] forts = {-1, -1, 0, 1, 0, 0, 1, -1, 1, 0};
        System.out.println(captureForts(forts));
    }

    public static int captureForts(int[] forts) {
        //记录1的位置
        List<Integer> one = new ArrayList<>();
        //记录-1的位置
        List<Integer> fuOne = new ArrayList<>();

        for (int i = 0; i < forts.length; i++) {
            if (forts[i] == 1) {
                one.add(i);
            }
            if (forts[i] == -1) {
                fuOne.add(i);
            }
        }


        int res = 0;

        for (Integer integer : one) {
            for (Integer integer1 : fuOne) {
                int temp = 0;
                boolean isBreak = false;
                for (int i = Math.min(integer, integer1) + 1; i < Math.max(integer, integer1); i++) {
                    if (forts[i] == 0) {
                        temp++;
                    }
                    if (forts[i] == -1 || forts[i] == 1) {
                        isBreak = true;
                        break;
                    }
                }
                if (!isBreak) {
                    res = Math.max(res, temp);
                }
            }
        }


        return res;
    }

}
